<?php
    if (isset($_REQUEST['old_password']) && 
        isset($_REQUEST['new_password']) &&
        isset($_REQUEST['confirm_password']) &&
        $_REQUEST['old_password'] != "" &&
        $_REQUEST['new_password'] != "" &&
        $_REQUEST['confirm_password'] != "")
    {
        global $db_manager;
    	$usr = $_SESSION['username'];
        $old = $_REQUEST['old_password'];
        $new = $_REQUEST['new_password'];
        $cnf = $_REQUEST['confirm_password'];
        $skn = "";
        $msg = "";
        $error = "";
        
        $xusers = new x_users($db_manager);
        switch ($xusers->change_password($usr, $old, $new, $cnf)) {
        	case 0 :
        		$ok = true;
        		$error = "";
        		break;
        	case -1:
        		$ok = false;
                $error = $labels["LBL_PASSWORDS_DOES_NOT_MATCH"];
                break;
        	case -2:
        		$ok = false;
        		$error = $labels["LBL_WRONG_PASSWORD"];
        		break;
        	default:
        	   $ok = false;
        	   $error = "";
        }
        
        if ($ok) {
        	$msg = $labels["LBL_PASSWORD_CHANGED"];
        	$skn = "showmessage";
        } else {
        	$msg = $error;
        	$skn = "changepsswd";
        }
        
    } else {
    	$msg = "";
    	$skn = "changepsswd";
    }
    
    $Skinner = new Skinner();
    $Skinner -> setSkin($skins_path.$skn);
    $Skinner -> registerVariable("message", $msg);
    $Skinner -> registerVariable("lbl_change_password", $labels["LBL_CHANGE_PASSWORD"]);
    $Skinner -> registerVariable("lbl_old_password", $labels["LBL_OLD_PASSWORD"]);
    $Skinner -> registerVariable("lbl_new_password", $labels["LBL_NEW_PASSWORD"]);
    $Skinner -> registerVariable("lbl_confirm_pswd", $labels["LBL_CONFIRM_PSWD"]);
    $Skinner -> registerVariable("lbl_ok", $labels["LBL_OK"]);
    $Skinner -> registerVariable("admin_root", $admin_root);
    $Skinner -> registerVariable("files_path", $files_path);
    $content=$Skinner->doSubstitution_FAST();
    
?>